﻿using System;
using System.Windows.Input;

namespace UIAuth.Examples.VM
{
    public class DelegateCommand : ICommand
    {
        public DelegateCommand()
        {
        }

        public DelegateCommand(Action<object> execute)
            : this(execute, null)
        {
        }

        public DelegateCommand(Action<object> execute, Func<object, bool> canExecute)
        {
            ExecuteCommand = execute;
            CanExecuteCommand = canExecute;
        }

        private Action<object> ExecuteCommand { get; set; }

        private Func<object, bool> CanExecuteCommand { get; set; }

        #region ICommand Members

        public void Execute(object parameter)
        {
            ExecuteCommand(parameter);
        }

        public bool CanExecute(object parameter)
        {
            if (CanExecuteCommand != null)
                return CanExecuteCommand(parameter);
            return true;
        }

        public event EventHandler CanExecuteChanged;

        #endregion
    }
}